#ifndef	__BFX_REF_XMLTEXTENCODER_H__
#define	__BFX_REF_XMLTEXTENCODER_H__

namespace BFX
{

// This class does special handling of text content for XML.  For example it will replace special characters with entities whenever necessary.
class REFXMLTextEncoder : public REFObject
{
public:
	REFXMLTextEncoder(REFUniTextWriter* pWriter);
	virtual ~REFXMLTextEncoder();

	void Write(UCHAR ch);
	void Write(const UniString& strText);
	
	void StartAttribute();
	void EndAttribute();

	//
	// Private implementation methods
	//
private:
	void WriteSurrogateChar(UCHAR lowChar, UCHAR highChar);
	void WriteEntityRefImpl(const UniString& str);
	void WriteCharEntityImpl(UCHAR ch);

private:
	static const int W_HIGH_SURROGATE_START		= 0x00d800;	// '\ud800';
	static const int W_HIGH_SURROGATE_END		= 0x00dbff;	// '\udbff';
	static const int W_LOW_SURROGATE_START		= 0x00dc00;	// '\udc00';
	static const int W_LOW_SURROGATE_END		= 0x00dfff;	// '\udfff';

	// true when writing out the content of attribute value
	bool	m_bInAttribute;
	REF<REFUniTextWriter>	m_pWriter;
};

}	//	namespace BFX

#endif	//	__BFX_REF_XMLTEXTENCODER_H__
